package _1域对象;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


// ServletContext 域对象

// getAttribute(key)
// setAttribute(key,value)
// removeAttribute(key)


@WebServlet("/test1")
public class Test1Servlet extends HttpServlet{
	
	int count2 = 0;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	{
		int count1 = 0;
		count1++;
//		System.out.println("test1 count1:"+count1+"<br />");
		resp.getWriter().print("test1 count1:"+count1+"<br />");
		
		count2++;
//		System.out.println("test1 count2:"+count2+"<br />");
		resp.getWriter().print("test1 count2:"+count2+"<br />");
		
		
		// 得到上下文对象
		ServletContext context = this.getServletContext();

		
		// 取信息
		Integer allCount = (Integer)context.getAttribute("allCount");
		if(allCount==null)
		{
			allCount=0;
		}
		allCount++;
		// 存入信息
		context.setAttribute("allCount",allCount);
		
		

		resp.getWriter().print("all count:"+allCount+"<br />");
		
	}
}